let username = localStorage.getItem("username");
new XMwiper({ sel: ".home-hero", autoPlay: true });
loadList();
loadList1();
//1-把用户名显示到页面上，并且获取购物车列表的商品数量
let uid = localStorage.getItem("uid");
if (username) {
  $(".denglu").html(username);
  $(".zhuce").css("display", "none");
  axios.get(cartListAPI, { params: { id: uid } }).then(function (res) {
    $(".txt-gouwuche").html(`购物车(${res.data.data.length})`);
  });
}
//2-1选项卡
$(".xiaomi_phone").on("mouseover",function(){
  // console.log(this);
  $("#xiaomi_phone").css("display","block")
  $(".header-listWrap").css({
              "height": "229px",
              "border-top": "1px #b0b0b0 solid",
              "border-bottom": "1px #b0b0b0 solid",
              "transition": "0.6s",
            });
})
$(".xiaomi_phone").on("mouseout",function(){
  $("#xiaomi_phone").css("display","none")
  $(".header-listWrap").css({
              "height": "0px",
              "border-top": "0px #b0b0b0 solid",
              "border-bottom": "0px #b0b0b0 solid",
              "transition": "0.6s",
            });
})
//2-2选项卡
$(".tv_phone").on("mouseover",function(){
  // console.log(this);
  $("#tv_phone").css("display","block")
  $(".header-listWrap").css({
              "height": "229px",
              "border-top": "1px #b0b0b0 solid",
              "border-bottom": "1px #b0b0b0 solid",
              "transition": "0.6s",
            });
})
$(".tv_phone").on("mouseout",function(){
  $("#tv_phone").css("display","none")
  $(".header-listWrap").css({
              "height": "0px",
              "border-top": "0px #b0b0b0 solid",
              "border-bottom": "0px #b0b0b0 solid",
              "transition": "0.6s",
            });
})
//2-3选项卡
$(".hongmi_phone").on("mouseover",function(){
  // console.log(this);
  $("#hongmi_phone").css("display","block")
  $(".header-listWrap").css({
              "height": "229px",
              "border-top": "1px #b0b0b0 solid",
              "border-bottom": "1px #b0b0b0 solid",
              "transition": "0.6s",
            });
})
$(".hongmi_phone").on("mouseout",function(){
  $("#hongmi_phone").css("display","none")
  $(".header-listWrap").css({
              "height": "0px",
              "border-top": "0px #b0b0b0 solid",
              "border-bottom": "0px #b0b0b0 solid",
              "transition": "0.6s",
            });
})

delnameFn();
//3-退出登录
//清除本地存储的username，
function delnameFn() {
let delname = document.querySelector("#delname");
// console.log(delname);
delname.onclick = function () {
    localStorage.removeItem("username");
    localStorage.setItem("uid","99999");//这个uid里商品为零
    location.reload();
};
};

usernameFn();
//4-显示用户名
//拿到本地的username，有就显示，没有就不显示，并且显示的时候阻止a标签的默认事件
function usernameFn() {
let username = document.querySelector("#username");
// console.log(username);
let name = localStorage.getItem("username");
// console.log(name);
if (name != null) {
    username.innerHTML = name + "欢迎";
    username.onclick = function (ev) {
    ev.preventDefault();
    };
};
};

//5-倒计时
let spans = document.querySelectorAll('.main-b-l span')
// console.log(spans);
let over = new Date('2021-6-25 0:0:0');
let time = setInterval(function() {
    let current = new Date()
    let miao = parseInt(over - current) / 1000;
    let m = parseInt(miao % 60);
    let f = parseInt((miao / 60) % 60);
    let s = parseInt(miao / 60 / 60);
    if (m < 10) {
        m = "0" + m;
    }
    if (f < 10) {
        f = "0" + f;
    }
    if (s < 10) {
        s = "0" + s;
    }
    spans.forEach((v, i) => {
        spans[0].innerHTML = s;
        spans[1].innerHTML = f
        spans[2].innerHTML = m
    })
});

 //6- 搜索栏
 $("#ssipt").on("input", function () {
  let url2 = `https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=${$(
    this
  ).val()}`;
  $.ajax({
    type: "get",
    url: url2,
    dataType: "jsonp", //jq创建script
    jsonp: "cb", //jq 会自动生成一个函数 cb=jq234234234234234,
    success(res) {
      // console.log("请求成功");
      // console.log(res);
      let { s } = res;
      // console.log({ s });
      let b = { s };
      // console.log(b.s[0]);
      let lib = $(`
        <li>${b.s[0]}</li>
        <li>${b.s[1]}</li>
        <li>${b.s[2]}</li>
        <li>${b.s[3]}</li>
        <li>${b.s[4]}</li>
        <li>${b.s[5]}</li>
        <li>${b.s[6]}</li>
        <li>${b.s[7]}</li>
        <li>${b.s[8]}</li>
        <li>${b.s[9]}</li>
    `);
      let node = $("#sslist");
      $(".sousuolist").css("display", "block");
      node.html(lib);
    },
  });
}).on("click",function(){
  $(".icon-sousuo").css("border-left","1px solid #ff6700")
  $(".sousuo").css("border","1px solid #ff6700")
  $(".sousuolist").css("border","1px solid #ff6700")
  $(".sousuolist").css("border-top","none")
  return false;
});
$("body").on("click",function(){
  $(".icon-sousuo").css("border-left","1px solid #e0e0e0")
  $(".sousuo").css("border","1px solid #e0e0e0")
  $(".sousuolist").css("border", "none")
})
$("#ssipt").on("blur", function () {
  $("#sslist").html("");
});

vueFU();
//7- 二级菜单
//获取对应的dom节点，循环遍历添加鼠标移入移出事件，让子元素显示和隐藏
function vueFU() {
let vueli = document.querySelectorAll(".sidebar li");
let vue2 = document.querySelectorAll(".vue2");
// console.log(vue2);
// console.log(vueli);
vueli.forEach((v, i) => {
  // console.log(v);
  v.onmouseover = function () {
    vue2[i].style.display = "block";
  };
  v.onmouseout = function () {
    vue2[i].style.display = "none";
  };
});
}